﻿#include "widget.h"
#include "ui_widget.h"
#include <QVBoxLayout>
#include <QMessageBox>
#include <QDebug>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    vbox = new QVBoxLayout;
    vbox->addWidget(ui->btn_about);
    vbox->addWidget(ui->btn_critical);
    vbox->addWidget(ui->btn_information);
    vbox->addWidget(ui->btn_question);
    vbox->addWidget(ui->btn_warning);
    setLayout(vbox);

    connect(ui->btn_about, &QPushButton::clicked, this, &Widget::getAbout);
    connect(ui->btn_critical, &QPushButton::clicked, this, &Widget::getCritical);
    connect(ui->btn_information, &QPushButton::clicked, this, &Widget::getInformation);
    connect(ui->btn_question, &QPushButton::clicked, this, &Widget::getQuestion);
    connect(ui->btn_warning, &QPushButton::clicked, this, &Widget::getWarning);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::getAbout()
{
    QMessageBox::about(this, "about关于对话框","我是你爹");
}

void Widget::getCritical()
{
    QMessageBox::critical(this, "错误对话框", "你弄错了，哈儿！");
}

void Widget::getInformation()
{
    QMessageBox::information(this, "information消息对话框", "喊你V我50！");
}

void Widget::getQuestion()
{
    QMessageBox::StandardButton btn = QMessageBox::question(this, "问题", "是否V我50？");
    if(btn == QMessageBox::Yes)
    {
        qDebug() << "是";
    }
    else if(btn == QMessageBox::No)
    {
        qDebug() << "不是";
    }
}

void Widget::getWarning()
{
    QMessageBox::warning(this, "警告", "给你两哈，不准这样子！！！", QMessageBox::Yes);
}
